/* 
 * File:   Search.hxx
 * Author: enric
 *
 * Created on 28 de enero de 2012, 13:25
 */

#ifndef SEARCH_HXX
#define	SEARCH_HXX

#include "GridWorld.hxx"
#include <queue>
#include <map>

class Search {
public:
    Search(std::string filename);
    float get_eval(Node& node);
    int get_heuristics(State& state);
    int get_acom(Node& node);
    int get_acom(Node& node, int value);
    
    void a_star();
    void a_star(Node& node, int boundary);
    void expand_node(Node& node);
    bool pruning(int boundary);
    
    void addPath(Node& node);
    bool isNodeInClosed(Node& node);
    void eraseElement(std::vector<Node*>& nodes, Node& node);
    Node& getBestFromOpen();
    void evaluateOpen();
 
    int values() { return m_values; }
    
    std::vector<Node*> path() { return m_path; }
    Grid_World world() { return m_grid_world; }
    
    int distance(unsigned int start_x, unsigned int final_x, unsigned int start_y, unsigned int final_y);
    void printValues() { std::cout << m_values << std::endl;
                         std::cout << m_closed.size() << std::endl; }
    void writeValues();
    
protected:
    Grid_World m_grid_world;
//    std::map<Action*, Node*> m_action_state;
//    std::map<Node*, Action*> m_state_action;
    std::vector<Node*> m_open;
    std::vector<Node*> m_closed;
    std::vector<Node*> m_path;
    std::stringstream m_out;
    int m_values;
};

#endif	/* SEARCH_HXX */

